import '../helper/uidata.dart';

import '../helper/dioHelper2.dart';

class DocReview {
  int ID;
  int TypeID;
  String TypeName;
  String StateList;
  String StateName;
  int StateMax;
  String Guid;
  String Title;
  String Content;
  int State;
  String FileSpaceId;
  String CreateTM;
  String UserID;
  String Remarks;

  DocReview(
      this.ID,
      this.TypeID,
      this.TypeName,
      this.StateList,
      this.StateName,
      this.StateMax,
      this.Guid,
      this.Title,
      this.Content,
      this.State,
      this.FileSpaceId,
      this.CreateTM,
      this.UserID,
      this.Remarks);
  DocReview.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        TypeID = json["TypeID"],
        TypeName = json["TypeName"],
        StateList = json["StateList"],
        StateName = json["StateName"],
        StateMax = json["StateMax"],
        Guid = json["Guid"],
        Title = json["Title"],
        Content = json["Content"],
        State = json["State"],
        FileSpaceId = json["FileSpaceId"],
        CreateTM = json["CreateTM"],
        UserID = json["UserID"],
        Remarks = json["Remarks"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'TypeID': TypeID,
        'TypeName': TypeName,
        'StateList': StateList,
        'StateName': StateName,
        'StateMax': StateMax,
        'Guid': Guid,
        'Title': Title,
        'Content': Content,
        'State': State,
        'FileSpaceId': FileSpaceId,
        'CreateTM': CreateTM,
        'UserID': UserID,
        'Remarks': Remarks,
      };
  static Future<bool> Add(DocReview x1) async {
    var response = await DioHelper.Post("/DocReview/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(DocReview x1) async {
    var response = await DioHelper.Post("/DocReview/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }


  static Future<bool> Sign(DocReview x1,String qm) async {
    var response = await DioHelper.Post("/DocReview/Sign?ID="+x1.ID.toString()+"&UserId="+UIData.CurrentUser!.Guid,qm);
    if (response.statusCode == 200) return true;
    return false;
  }


  static Future<DocReview?> GetByID(int ID) async {
    var response =
        await DioHelper.Get("/DocReview/GetByID?ID=" + ID.toString(), {});

    if (response.statusCode == 200) return new DocReview.fromJson(response.data);
    return null;
  }


  static Future<bool> Delete(DocReview x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/DocReview/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<DocReview?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/DocReview/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200)
      return new DocReview.fromJson(response.data);
    return null;
  }


    static Future<List<DocReview>> GetList(
      int pageIndex, int pageSize, int state,int typeId) async {
    var response = await DioHelper.Get(
        "/DocReview/GetList?p1=" +
            pageIndex.toString() +
            "&ps=" +
            pageSize.toString() +
            "&st=" +
            state.toString() +
            "&t1=" +
            typeId.toString() +
            "&userID=" +
            UIData.CurrentUser!.Guid,
        {});
  
    var list1 = <DocReview>[];
    if (response.data==null){
      return list1;
    }
    
    if (response.statusCode == 200) {
      //print(response.data);
      for (var x in response.data) {
        list1.add(new DocReview.fromJson(x));
      }
    }
    return list1;
  }


  static Future<List<DocReview>> GetAllList() async {
    var response = await DioHelper.Get("/DocReview/GetAllList", {});
    var list1 = <DocReview>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new DocReview.fromJson(x));
      }
    }
    return list1;
  }
}
